package com.youhome.business.controller;

import com.youhome.common.exception.CustomException;
import com.youhome.common.response.Result;
import com.youhome.common.response.ResultCode;
import com.youhome.common.response.ResultPage;
import com.youhome.service.model.Principal;
import com.youhome.service.service.BUserService;
import com.youhome.service.service.ReportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

/**
 * Created by chen365 on 2018/08/13.
 */
@RestController
@RequestMapping("/user")
@Api(tags = "用户")
public class UserController {
    @Autowired
    private ReportService reportService;
    @Autowired
    private BUserService bUserService;

    @ApiOperation(value = "用户房产报告", notes = "用户房产报告")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "int", name = "pageNumber", value = "页码", required = true, paramType = "path")
    })
    @GetMapping("report/list/{pageNumber}")
    public Object reportList(@PathVariable Integer pageNumber, @ApiIgnore @AuthenticationPrincipal Principal principal) throws CustomException {
        Integer pageSize = 10;
        return new ResultPage(ResultCode.SUCCESS, reportService.selectByPage(principal,pageNumber, pageSize));
    }

    @ApiOperation(value = "报告可下载数", notes = "报告可下载数")
    @GetMapping("report/count")
    public Object reportCount() throws CustomException {
        return new Result(ResultCode.SUCCESS, bUserService.selectReportCount());
    }
}
